from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        ALTER TABLE `chat_message` MODIFY COLUMN `owner_user_id` INT;
        ALTER TABLE `chat_session` ADD `owner_key_id` INT NOT NULL;
        ALTER TABLE `chat_session` ADD CONSTRAINT `fk_chat_ses_chat_exc_7ec34fdf` FOREIGN KEY (`owner_key_id`) REFERENCES `chat_exclusive_key` (`id`) ON DELETE CASCADE;"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        ALTER TABLE `chat_session` DROP FOREIGN KEY `fk_chat_ses_chat_exc_7ec34fdf`;
        ALTER TABLE `chat_message` MODIFY COLUMN `owner_user_id` INT NOT NULL;
        ALTER TABLE `chat_session` DROP COLUMN `owner_key_id`;"""
